<?php

/**
 * Get the barycentre from array of value
 * Ref to : http://fr.wikipedia.org/wiki/Barycentre_(g%C3%A9om%C3%A9trie_%C3%A9l%C3%A9mentaire)
 * We work in one dimention so we just nee x axis
 * @author Christian DRAMSY <christian.dramsy@gmail.com>
 * @param type $a_f_arrayOfValue
 */
function f_getBarycentre($a_f_arrayOfValue) {
    $f_numerator = 0;
    $f_denominator = 0;
    foreach ($a_f_arrayOfValue as $f_value) {
        $f_numerator += ($f_value * $f_value);
        $f_denominator += $f_value;
    }
    if ($f_denominator == 0) {
        return null;
    }
    return ($f_numerator / $f_denominator);
}

?>
